package exercises;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-02-22
 * Time:20:11
 */
@SuppressWarnings("all")
public class Exercise2 {
    public static void main(String[] args) {
        Car car = new Car("宝马", 400000);
        Car car2 = new Car("宾利", 5000000);
        ArrayList<Car> cars = new ArrayList<>();
        cars.add(car);
        cars.add(car2);
        System.out.println(cars);//[Car{name='宝马', price=400000}, Car{name='宾利', price=5000000}]
        cars.remove(car);
        System.out.println(cars);//[Car{name='宾利', price=5000000}]
        System.out.println(cars.contains(car));//false
        System.out.println(cars.size());//1
        System.out.println(cars.isEmpty());//false
        cars.addAll(cars);
        System.out.println(cars);//[Car{name='宾利', price=5000000}, Car{name='宾利', price=5000000}]
        System.out.println(cars.containsAll(cars));//true
//        cars.removeAll(cars);
        for (Car car1 : cars) {
            System.out.println(car1);
//            Car{name='宾利', price=5000000}
//            Car{name='宾利', price=5000000}
        }
        Iterator<Car> iterator = cars.iterator();
        while (iterator.hasNext()) {
            Car next = iterator.next();
            System.out.println(next);
//            Car{name='宾利', price=5000000}
//            Car{name='宾利', price=5000000}
        }
    }
}

@SuppressWarnings("all")
class Car {
    private String name;
    private int price;

    public Car(String name, int price) {
        this.name = name;
        this.price = price;
    }

    @Override
    public String toString() {
        return "Car{" + "name='" + name + '\'' + ", price=" + price + '}';
    }
}